package com.hyt.it.ogt.kq.common.gov.enums;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * redis缓存key枚举
 */
@Getter
public enum CacheKeyEnum implements BaseEnum<String>{
    CREATE_ADMISSION_TICKET_KEY("CREATE_ADMISSION_TICKET_KEY", 30 * 60L, "准考证"),
    CREATE_ROOM_DATA_KEY("CREATE_ROOM_DATA_KEY", 30 * 60L, "生成考务包事务key"),
    CREATE_MOCK_ROOM_DATA_KEY("CREATE_MOCK_ROOM_DATA_KEY", 30 * 60L, "生成模拟测试考务包事务key"),
    CREATE_ROOM_DATA_PROGRESS_TOTAL_KEY("CREATE_ROOM_DATA_PROGRESS_TOTAL_KEY", 24 * 60 * 60L, "生成考务包过程总量key"),
    CREATE_MOCK_ROOM_DATA_PROGRESS_TOTAL_KEY("CREATE_MOCK_ROOM_DATA_PROGRESS_TOTAL_KEY", 24 * 60 * 60L, "生成模拟测试考务包过程总量key"),
    CREATE_ROOM_DATA_PROGRESS_KEY("CREATE_ROOM_DATA_PROGRESS_KEY", 60 * 60L, "生成考务包过程完成数量key"),
    CREATE_MOCK_ROOM_DATA_PROGRESS_KEY("CREATE_MOCK_ROOM_DATA_PROGRESS_KEY", 60 * 60L, "生成模拟测试考务包过程完成数量key"),
    EXPORT_ADMISSION_TICKET_KEY("EXPORT_ADMISSION_TICKET_KEY", 30 * 60L, "导出准考证事务key"),
    EXPORT_ADMISSION_TICKET_PROGRESS_TOTAL_KEY("EXPORT_ADMISSION_TICKET_PROGRESS_TOTAL_KEY", 24 * 60 * 60L, "获取导出准考证过程总量key"),
    EXPORT_ADMISSION_TICKET_PROGRESS_KEY("EXPORT_ADMISSION_TICKET_PROGRESS_KEY", 60 * 60L, "获取导出准考证过程完成数量key"),
    CREATE_TASK_TIME_KEY("CREATE_TASK_TIME_KEY", 30 * 60L, "批次"),
    CREATE_TIME_ROOM_CANDIDATE_KEY("CREATE_TIME_ROOM_CANDIDATE_KEY", -1L, "沒有用"),
    CREATE_ADMISSION_TICKET_PROGRESS_KEY("CREATE_ADMISSION_TICKET_PROGRESS_KEY", 60 * 60L, "生成准考证进度"),
    CREATE_ADMISSION_TICKET_PROGRESS_TOTAL_KEY("CREATE_ADMISSION_TICKET_PROGRESS_TOTAL_KEY", 24 * 60 * 60L, "生成准考证进度"),
    ARRANGE_TOTAL_KEY("ARRANGE_TOTAL_KEY", -1L, "沒有用"),
    ARRANGE_PROGRESS_KEY("ARRANGE_PROGRESS_KEY", -1L, "沒有用"),
    ARRANGE_CANDIDATE_KEY("ARRANGE_CANDIDATE_KEY", 30 * 60L, "正在执行编排(分布式锁)，避免多用户操作同一任务"),
    DATA_LOCK_KEY("DATA_LOCK_KEY", 60 * 60L, "更新任务锁定"),
    DATA_LOCK_TOTAL_KEY("DATA_LOCK_TOTAL_KEY", 24 * 60 * 60L, "编排的考生进度总数"),
    DATA_LOCK_PROGRESS_KEY("DATA_LOCK_PROGRESS_KEY", 24 * 60* 60L, "更新任务锁定进度"),
    DATA_LOCK_ERROR_KEY("DATA_LOCK_ERROR_KEY", 24 * 60* 60L, "更新任务锁定报错"),
    IMPORT_CANDIDATE_PHOTO("IMPORT_CANDIDATE_PHOTO_KEY", 30 * 60L, "批量导入照片，zip文件"),
    USER_TIME_CACHE_KEY("USER_TIME_CACHE_KEY", 5 * 60L, "考务人员与批次关系"),
    USER_TIME_ADMIN_CACHE_KEY("USER_TIME_ADMIN_CACHE_KEY", 5 * 60L, "考务人员与批次关系 -- 管理员"),
    USER_TASK_CACHE_KEY("USER_TASK_CACHE_KEY", 5 * 60L, "考务人员与任务关系"),
    TEMPLATE_EXAMPLE_CACHE_KEY("TEMPLATE_EXAMPLE", 30 * 24 * 60 * 60L, "机构模板样例"),
    GOV_BING_BM_TOTAL_CACHE_KEY("GOV_BING_BM_TOTAL_CACHE_KEY", 30 * 24 * 60 * 60L, "考务绑定报名，进度最大值"),
    GOV_BING_BM_LOCK_KEY("GOV_BING_BM_LOCK_KEY", 30 * 24 * 60 * 60L, "考务绑定报名，锁定"),
    GOV_BING_BM_ERROR_CACHE_KEY("GOV_BING_BM_ERROR_CACHE_KEY", 30 * 24 * 60 * 60L, "考务绑定报名，错误"),
    GOV_BING_BM_PROCESS_CACHE_KEY("GOV_BING_BM_PROCESS_CACHE_KEY", 30 * 24 * 60 * 60L, "考务绑定报名，进度"),
    GOV_OFFICE_AREA_CACHE_MAP_KEY("GOV_OFFICE_AREA_CACHE_MAP_KEY",60 * 60L, "平台区域信息"),
    GOV_OFFICE_AREA_CACHE_LIST_KEY("GOV_OFFICE_AREA_CACHE_LIST_KEY",60 * 60L, "平台区域信息"),
    ;
    //统一分隔符
    public static final String CACHE_SEPARATOR = ":";
    private String code;
    private Long expireSeconds;
    private String msg;

    CacheKeyEnum(String code, Long expireSeconds, String msg) {
        this.code = code;
        this.expireSeconds = expireSeconds;
        this.msg = msg;
    }

    public String getCacheEnumKey(Object... params) {
        List<Object> objectList = Arrays.stream(params).collect(Collectors.toList());
        objectList.add(0, getCode());
        return StringUtils.joinWith(CACHE_SEPARATOR, objectList.toArray());
    }

    
    public static String getKey(Object... params) {
        return StringUtils.joinWith(CACHE_SEPARATOR, params);
    }

}
